home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / control / client / misc / settingsscreen.cs < prev    next >
Encoding:
Text File  |  2006-09-25  |  15.5 KB  |  562 lines

  1. function SetupScreen::setPane(%this, %pane)
  2. {
  3.    OptAudioPane.setVisible(false);
  4.    OptGraphicsPane.setVisible(false);
  5.    OptNetworkPane.setVisible(false);
  6.    OptControlsPane.setVisible(false);
  7.    ("Opt" @ %pane @ "Pane").setVisible(true);
  8.    OptRemapList.fillList();
  9. }
  10.  
  11. function SetupScreen::onWake(%this)
  12. {
  13.    %this.setPane(Graphics);
  14.    %buffer = getDisplayDeviceList();
  15.    %count = getFieldCount( %buffer );
  16.    OptGraphicsDriverMenu.clear();
  17.    OptScreenshotMenu.init();
  18.    OptScreenshotMenu.setValue($pref::Video::screenShotFormat);
  19.    for(%i = 0; %i < %count; %i++)
  20.       OptGraphicsDriverMenu.add(getField(%buffer, %i), %i);
  21.    %selId = OptGraphicsDriverMenu.findText( $pref::Video::displayDevice );
  22.     if ( %selId == -1 )
  23.         %selId = 0; // shouldn't ever happen
  24.     OptGraphicsDriverMenu.setSelected( %selId );
  25.     OptGraphicsDriverMenu.onSelect( %selId, "" );
  26.  
  27.    // Audio
  28.    OptAudioUpdate();
  29.    OptAudioVolumeMaster.setValue( $pref::Audio::masterVolume);
  30.    OptAudioVolumeShell.setValue(  $pref::Audio::channelVolume[$GuiAudioType]);
  31.    OptAudioVolumeSim.setValue(    $pref::Audio::channelVolume[$SimAudioType]);
  32.    OptAudioDriverList.clear();
  33.    OptAudioDriverList.add("OpenAL", 1);
  34.    OptAudioDriverList.add("none", 2);
  35.    %selId = OptAudioDriverList.findText($pref::Audio::driver);
  36.     if ( %selId == -1 )
  37.         %selId = 0; // How did THAT happen?
  38.     OptAudioDriverList.setSelected( %selId );
  39.     OptAudioDriverList.onSelect( %selId, "" );
  40. }
  41.  
  42. function SetupScreen::onSleep(%this)
  43. {
  44.    // write out the control config into the fps/config.cs file
  45.    echo("function SetupScreen::onSleep(%this)function SetupScreen::onSleep(%this)function SetupScreen::onSleep(%this)");
  46.    PlayerKeymap.save( "~/client/config.cs" );//KCF
  47.  
  48. }
  49.  
  50. function OptGraphicsDriverMenu::onSelect( %this, %id, %text )
  51. {
  52.     // Attempt to keep the same res and bpp settings:
  53.     if ( OptGraphicsResolutionMenu.size() > 0 )
  54.         %prevRes = OptGraphicsResolutionMenu.getText();
  55.     else
  56.         %prevRes = getWords( $pref::Video::resolution, 0, 1 );
  57.  
  58.     // Check if this device is full-screen only:
  59.     if ( isDeviceFullScreenOnly( %this.getText() ) )
  60.     {
  61.         OptGraphicsFullscreenToggle.setValue( true );
  62.         OptGraphicsFullscreenToggle.setActive( false );
  63.         OptGraphicsFullscreenToggle.onAction();
  64.     }
  65.     else
  66.         OptGraphicsFullscreenToggle.setActive( true );
  67.  
  68.     if ( OptGraphicsFullscreenToggle.getValue() )
  69.     {
  70.         if ( OptGraphicsBPPMenu.size() > 0 )
  71.             %prevBPP = OptGraphicsBPPMenu.getText();
  72.         else
  73.             %prevBPP = getWord( $pref::Video::resolution, 2 );
  74.     }
  75.  
  76.     // Fill the resolution and bit depth lists:
  77.     OptGraphicsResolutionMenu.init( %this.getText(), OptGraphicsFullscreenToggle.getValue() );
  78.     OptGraphicsBPPMenu.init( %this.getText() );
  79.  
  80.     // Try to select the previous settings:
  81.     %selId = OptGraphicsResolutionMenu.findText( %prevRes );
  82.     if ( %selId == -1 )
  83.         %selId = 0;
  84.     OptGraphicsResolutionMenu.setSelected( %selId );
  85.  
  86.     if ( OptGraphicsFullscreenToggle.getValue() )
  87.     {
  88.         %selId = OptGraphicsBPPMenu.findText( %prevBPP );
  89.         if ( %selId == -1 )
  90.             %selId = 0;
  91.         OptGraphicsBPPMenu.setSelected( %selId );
  92.         OptGraphicsBPPMenu.setText( OptGraphicsBPPMenu.getTextById( %selId ) );
  93.     }
  94.     else
  95.         OptGraphicsBPPMenu.setText( "Default" );
  96.  
  97. }
  98.  
  99. function OptGraphicsResolutionMenu::init( %this, %device, %fullScreen )
  100. {
  101.     %this.clear();
  102.     %resList = getResolutionList( %device );
  103.     %resCount = getFieldCount( %resList );
  104.     %deskRes = getDesktopResolution();
  105.  
  106.    %count = 0;
  107.     for ( %i = 0; %i < %resCount; %i++ )
  108.     {
  109.         %res = getWords( getField( %resList, %i ), 0, 1 );
  110.  
  111.         if ( !%fullScreen )
  112.         {
  113.             if ( firstWord( %res ) >= firstWord( %deskRes ) )
  114.                 continue;
  115.             if ( getWord( %res, 1 ) >= getWord( %deskRes, 1 ) )
  116.                 continue;
  117.         }
  118.  
  119.         // Only add to list if it isn't there already:
  120.         if ( %this.findText( %res ) == -1 )
  121.       {
  122.             %this.add( %res, %count );
  123.          %count++;
  124.       }
  125.     }
  126. }
  127.  
  128. function OptGraphicsFullscreenToggle::onAction(%this)
  129. {
  130.    Parent::onAction();
  131.    %prevRes = OptGraphicsResolutionMenu.getText();
  132.  
  133.    // Update the resolution menu with the new options
  134.    OptGraphicsResolutionMenu.init( OptGraphicsDriverMenu.getText(), %this.getValue() );
  135.  
  136.    // Set it back to the previous resolution if the new mode supports it.
  137.    %selId = OptGraphicsResolutionMenu.findText( %prevRes );
  138.    if ( %selId == -1 )
  139.        %selId = 0;
  140.      OptGraphicsResolutionMenu.setSelected( %selId );
  141. }
  142.  
  143.  
  144. function OptGraphicsBPPMenu::init( %this, %device )
  145. {
  146.     %this.clear();
  147.  
  148.     if ( %device $= "Voodoo2" )
  149.         %this.add( "16", 0 );
  150.     else
  151.     {
  152.         %resList = getResolutionList( %device );
  153.         %resCount = getFieldCount( %resList );
  154.       %count = 0;
  155.         for ( %i = 0; %i < %resCount; %i++ )
  156.         {
  157.             %bpp = getWord( getField( %resList, %i ), 2 );
  158.  
  159.             // Only add to list if it isn't there already:
  160.             if ( %this.findText( %bpp ) == -1 )
  161.          {
  162.                 %this.add( %bpp, %count );
  163.             %count++;
  164.          }
  165.         }
  166.     }
  167. }
  168.  
  169. function OptScreenshotMenu::init( %this )
  170. {
  171.    if( %this.findText("PNG") == -1 )
  172.       %this.add("PNG", 0);
  173.    if( %this.findText("JPEG") == - 1 )
  174.       %this.add("JPEG", 1);
  175. }
  176.  
  177. function SetupScreen::applyGraphics( %this )
  178. {
  179.     %newDriver = OptGraphicsDriverMenu.getText();
  180.     %newRes = OptGraphicsResolutionMenu.getText();
  181.     %newBpp = OptGraphicsBPPMenu.getText();
  182.     %newFullScreen = OptGraphicsFullscreenToggle.getValue();
  183.     $pref::Video::screenShotFormat = OptScreenshotMenu.getText();
  184.  
  185.     if ( %newDriver !$= $pref::Video::displayDevice )
  186.     {
  187.         setDisplayDevice( %newDriver, firstWord( %newRes ), getWord( %newRes, 1 ), %newBpp, %newFullScreen );
  188.         //SetupScreen::deviceDependent( %this );
  189.     }
  190.     else
  191.         setScreenMode( firstWord( %newRes ), getWord( %newRes, 1 ), %newBpp, %newFullScreen );
  192. }
  193.  
  194.  
  195.  
  196. $RemapCount = 0;
  197. $RemapName[$RemapCount] = "Forward";
  198. $RemapCmd[$RemapCount] = "moveforward";
  199. $RemapCount++;
  200. $RemapName[$RemapCount] = "Backward";
  201. $RemapCmd[$RemapCount] = "movebackward";
  202. $RemapCount++;
  203. $RemapName[$RemapCount] = "Strafe Left";
  204. $RemapCmd[$RemapCount] = "moveleft";
  205. $RemapCount++;
  206. $RemapName[$RemapCount] = "Strafe Right";
  207. $RemapCmd[$RemapCount] = "moveright";
  208. $RemapCount++;
  209. $RemapName[$RemapCount] = "Turn Left";
  210. $RemapCmd[$RemapCount] = "turnLeft";
  211. $RemapCount++;
  212. $RemapName[$RemapCount] = "Turn Right";
  213. $RemapCmd[$RemapCount] = "turnRight";
  214. $RemapCount++;
  215. $RemapName[$RemapCount] = "Look Up";
  216. $RemapCmd[$RemapCount] = "panUp";
  217. $RemapCount++;
  218. $RemapName[$RemapCount] = "Look Down";
  219. $RemapCmd[$RemapCount] = "panDown";
  220. $RemapCount++;
  221. $RemapName[$RemapCount] = "Jump";
  222. $RemapCmd[$RemapCount] = "jump";
  223. $RemapCount++;
  224. $RemapName[$RemapCount] = "Fire Weapon";
  225. $RemapCmd[$RemapCount] = "mouseFire";
  226. $RemapCount++;
  227. $RemapName[$RemapCount] = "Adjust Zoom";
  228. $RemapCmd[$RemapCount] = "setZoomFov";
  229. $RemapCount++;
  230. $RemapName[$RemapCount] = "Toggle Zoom";
  231. $RemapCmd[$RemapCount] = "toggleZoom";
  232. $RemapCount++;
  233. $RemapName[$RemapCount] = "Free Look";
  234. $RemapCmd[$RemapCount] = "toggleFreeLook";
  235. $RemapCount++;
  236. $RemapName[$RemapCount] = "Switch 1st/3rd";
  237. $RemapCmd[$RemapCount] = "toggleFirstPerson";
  238. $RemapCount++;
  239. $RemapName[$RemapCount] = "Toggle Message Hud";
  240. $RemapCmd[$RemapCount] = "toggleMessageHud";
  241. $RemapCount++;
  242. $RemapName[$RemapCount] = "Message Hud PageUp";
  243. $RemapCmd[$RemapCount] = "pageMessageHudUp";
  244. $RemapCount++;
  245. $RemapName[$RemapCount] = "Message Hud PageDown";
  246. $RemapCmd[$RemapCount] = "pageMessageHudDown";
  247. $RemapCount++;
  248. $RemapName[$RemapCount] = "Resize Message Hud";
  249. $RemapCmd[$RemapCount] = "resizeMessageHud";
  250. $RemapCount++;
  251. $RemapName[$RemapCount] = "Toggle Camera";
  252. $RemapCmd[$RemapCount] = "toggleCamera";
  253. $RemapCount++;
  254. $RemapName[$RemapCount] = "Drop Camera at Player";
  255. $RemapCmd[$RemapCount] = "dropCameraAtPlayer";
  256. $RemapCount++;
  257. $RemapName[$RemapCount] = "Drop Player at Camera";
  258. $RemapCmd[$RemapCount] = "dropPlayerAtCamera";
  259. $RemapCount++;
  260.  
  261.  
  262. function restoreDefaultMappings()
  263. {
  264.    PlayerKeymap.delete();//KCF
  265.    exec( "~/client/scripts/default.bind.cs" );
  266.    OptRemapList.fillList();
  267. }
  268.  
  269. function getMapDisplayName( %device, %action )
  270. {
  271.     if ( %device $= "keyboard" )
  272.         return( %action );
  273.     else if ( strstr( %device, "mouse" ) != -1 )
  274.     {
  275.         // Substitute "mouse" for "button" in the action string:
  276.         %pos = strstr( %action, "button" );
  277.         if ( %pos != -1 )
  278.         {
  279.             %mods = getSubStr( %action, 0, %pos );
  280.             %object = getSubStr( %action, %pos, 1000 );
  281.             %instance = getSubStr( %object, strlen( "button" ), 1000 );
  282.             return( %mods @ "mouse" @ ( %instance + 1 ) );
  283.         }
  284.         else
  285.             error( "Mouse input object other than button passed to getDisplayMapName!" );
  286.     }
  287.     else if ( strstr( %device, "joystick" ) != -1 )
  288.     {
  289.         // Substitute "joystick" for "button" in the action string:
  290.         %pos = strstr( %action, "button" );
  291.         if ( %pos != -1 )
  292.         {
  293.             %mods = getSubStr( %action, 0, %pos );
  294.             %object = getSubStr( %action, %pos, 1000 );
  295.             %instance = getSubStr( %object, strlen( "button" ), 1000 );
  296.             return( %mods @ "joystick" @ ( %instance + 1 ) );
  297.         }
  298.         else
  299.        {
  300.           %pos = strstr( %action, "pov" );
  301.          if ( %pos != -1 )
  302.          {
  303.             %wordCount = getWordCount( %action );
  304.             %mods = %wordCount > 1 ? getWords( %action, 0, %wordCount - 2 ) @ " " : "";
  305.             %object = getWord( %action, %wordCount - 1 );
  306.             switch$ ( %object )
  307.             {
  308.                case "upov":   %object = "POV1 up";
  309.                case "dpov":   %object = "POV1 down";
  310.                case "lpov":   %object = "POV1 left";
  311.                case "rpov":   %object = "POV1 right";
  312.                case "upov2":  %object = "POV2 up";
  313.                case "dpov2":  %object = "POV2 down";
  314.                case "lpov2":  %object = "POV2 left";
  315.                case "rpov2":  %object = "POV2 right";
  316.                default:       %object = "??";
  317.             }
  318.             return( %mods @ %object );
  319.          }
  320.          else
  321.             error( "Unsupported Joystick input object passed to getDisplayMapName!" );
  322.       }
  323.     }
  324.  
  325.     return( "??" );
  326. }
  327.  
  328. function buildFullMapString( %index )
  329. {
  330.    %name       = $RemapName[%index];
  331.    %cmd        = $RemapCmd[%index];
  332.  
  333.     %temp = PlayerKeymap.getBinding( %cmd );//KCF
  334.    %device = getField( %temp, 0 );
  335.    %object = getField( %temp, 1 );
  336.    if ( %device !$= "" && %object !$= "" )
  337.        %mapString = getMapDisplayName( %device, %object );
  338.    else
  339.       %mapString = "";
  340.  
  341.     return( %name TAB %mapString );
  342. }
  343.  
  344. function OptRemapList::fillList( %this )
  345. {
  346.     %this.clear();
  347.    for ( %i = 0; %i < $RemapCount; %i++ )
  348.       %this.addRow( %i, buildFullMapString( %i ) );
  349. }
  350.  
  351. //------------------------------------------------------------------------------
  352. function OptRemapList::doRemap( %this )
  353. {
  354.     %selId = %this.getSelectedId();
  355.    %name = $RemapName[%selId];
  356.  
  357.     OptRemapText.setValue( "REMAP \"" @ %name @ "\"" );
  358.     OptRemapInputCtrl.index = %selId;
  359.     Canvas.pushDialog( RemapDlg );
  360. }
  361.  
  362. //------------------------------------------------------------------------------
  363. function redoMapping( %device, %action, %cmd, %oldIndex, %newIndex )
  364. {
  365.     //%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
  366.     PlayerKeymap.bind( %device, %action, %cmd );//KCF
  367.     OptRemapList.setRowById( %oldIndex, buildFullMapString( %oldIndex ) );
  368.     OptRemapList.setRowById( %newIndex, buildFullMapString( %newIndex ) );
  369. }
  370.  
  371. //------------------------------------------------------------------------------
  372. function findRemapCmdIndex( %command )
  373. {
  374.     for ( %i = 0; %i < $RemapCount; %i++ )
  375.     {
  376.         if ( %command $= $RemapCmd[%i] )
  377.             return( %i );
  378.     }
  379.     return( -1 );
  380. }
  381.  
  382. function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
  383. {
  384.     //error( "** onInputEvent called - device = " @ %device @ ", action = " @ %action @ " **" );
  385.     Canvas.popDialog( RemapDlg );
  386.  
  387.     // Test for the reserved keystrokes:
  388.     if ( %device $= "keyboard" )
  389.     {
  390.       // Cancel...
  391.       if ( %action $= "escape" )
  392.       {
  393.          // Do nothing...
  394.            return;
  395.       }
  396.     }
  397.  
  398.    %cmd  = $RemapCmd[%this.index];
  399.    %name = $RemapName[%this.index];
  400.  
  401.     // First check to see if the given action is already mapped:
  402.     %prevMap = PlayerKeymap.getCommand( %device, %action );//KCF
  403.    if ( %prevMap !$= %cmd )
  404.    {
  405.        if ( %prevMap $= "" )
  406.        {
  407.          PlayerKeymap.bind( %device, %action, %cmd );//KCF
  408.            OptRemapList.setRowById( %this.index, buildFullMapString( %this.index ) );
  409.        }
  410.        else
  411.        {
  412.          %mapName = getMapDisplayName( %device, %action );
  413.            %prevMapIndex = findRemapCmdIndex( %prevMap );
  414.            if ( %prevMapIndex == -1 )
  415.                MessageBoxOK( "REMAP FAILED", "\"" @ %mapName @ "\" is already bound to a non-remappable command!" );
  416.            else
  417.          {
  418.             %prevCmdName = $RemapName[%prevMapIndex];
  419.                MessageBoxYesNo( "WARNING",
  420.                    "\"" @ %mapName @ "\" is already bound to \""
  421.                        @ %prevCmdName @ "\"!\nDo you want to undo this mapping?",
  422.                    "redoMapping(" @ %device @ ", \"" @ %action @ "\", \"" @ %cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");", "" );
  423.          }
  424.            return;
  425.        }
  426.    }
  427. }
  428.  
  429. // Audio
  430. function OptAudioUpdate()
  431. {
  432.    // set the driver text
  433.    %text =   "Vendor: " @ alGetString("AL_VENDOR") @
  434.            "\nVersion: " @ alGetString("AL_VERSION") @
  435.            "\nRenderer: " @ alGetString("AL_RENDERER") @
  436.            "\nExtensions: " @ alGetString("AL_EXTENSIONS");
  437.    OptAudioInfo.setText(%text);
  438.  
  439. }
  440.  
  441.  
  442. // Channel 0 is unused in-game, but is used here to test master volume.
  443.  
  444. new AudioDescription(AudioChannel0)
  445. {
  446.    volume   = 1.0;
  447.    isLooping= false;
  448.    is3D     = false;
  449.    type     = 0;
  450. };
  451.  
  452. new AudioDescription(AudioChannel1)
  453. {
  454.    volume   = 1.0;
  455.    isLooping= false;
  456.    is3D     = false;
  457.    type     = 1;
  458. };
  459.  
  460. new AudioDescription(AudioChannel2)
  461. {
  462.    volume   = 1.0;
  463.    isLooping= false;
  464.    is3D     = false;
  465.    type     = 2;
  466. };
  467.  
  468. new AudioDescription(AudioChannel3)
  469. {
  470.    volume   = 1.0;
  471.    isLooping= false;
  472.    is3D     = false;
  473.    type     = 3;
  474. };
  475.  
  476. new AudioDescription(AudioChannel4)
  477. {
  478.    volume   = 1.0;
  479.    isLooping= false;
  480.    is3D     = false;
  481.    type     = 4;
  482. };
  483.  
  484. new AudioDescription(AudioChannel5)
  485. {
  486.    volume   = 1.0;
  487.    isLooping= false;
  488.    is3D     = false;
  489.    type     = 5;
  490. };
  491.  
  492. new AudioDescription(AudioChannel6)
  493. {
  494.    volume   = 1.0;
  495.    isLooping= false;
  496.    is3D     = false;
  497.    type     = 6;
  498. };
  499.  
  500. new AudioDescription(AudioChannel7)
  501. {
  502.    volume   = 1.0;
  503.    isLooping= false;
  504.    is3D     = false;
  505.    type     = 7;
  506. };
  507.  
  508. new AudioDescription(AudioChannel8)
  509. {
  510.    volume   = 1.0;
  511.    isLooping= false;
  512.    is3D     = false;
  513.    type     = 8;
  514. };
  515.  
  516. $AudioTestHandle = 0;
  517.  
  518. function OptAudioUpdateMasterVolume(%volume)
  519. {
  520.    if (%volume == $pref::Audio::masterVolume)
  521.       return;
  522.    alxListenerf(AL_GAIN_LINEAR, %volume);
  523.    $pref::Audio::masterVolume = %volume;
  524.    if (!alxIsPlaying($AudioTestHandle))
  525.    {
  526.       $AudioTestHandle = alxCreateSource("AudioChannel0", expandFilename("~/data/sound/test.wav"));
  527.       alxPlay($AudioTestHandle);
  528.    }
  529. }
  530.  
  531.  
  532. function OptAudioUpdateChannelVolume(%channel, %volume)
  533. {
  534.    if (%channel < 1 || %channel > 8)
  535.       return;
  536.  
  537.    if (%volume == $pref::Audio::channelVolume[%channel])
  538.       return;
  539.  
  540.    alxSetChannelVolume(%channel, %volume);
  541.    $pref::Audio::channelVolume[%channel] = %volume;
  542.    if (!alxIsPlaying($AudioTestHandle))
  543.    {
  544.       $AudioTestHandle = alxCreateSource("AudioChannel"@%channel, expandFilename("~/data/sound/test.wav"));
  545.       alxPlay($AudioTestHandle);
  546.    }
  547. }
  548.  
  549.  
  550. function OptAudioDriverList::onSelect( %this, %id, %text )
  551. {
  552.    if (%text $= "")
  553.       return;
  554.  
  555.    if ($pref::Audio::driver $= %text)
  556.       return;
  557.  
  558.    $pref::Audio::driver = %text;
  559.    OpenALInit();
  560. }
  561.  
  562.